/*

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#import "DoomApp.h"
#include "iPhone_Routines.h"

  enum{
    kFACEUP = 0,
    kNORMAL = 1,
    kUPSIDEDOWN = 2,
    kLANDL = 3,
    kLANDR = 4,
    kFACEDOWN = 6
  };

@implementation DoomApp
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

//        _screenOrientation = 0;
	_window = [[UIWindow alloc] initWithContentRect:
		 [UIHardware fullScreenApplicationContentRect]
	];

	struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
	rect.origin.x = rect.origin.y = 0.0f;
	rect.size.width = 480;
	rect.size.height = 320;
//rect.origin.y +=120;

/*	float transparentComponents[4] = { 1., 0.0, 0., 1. };
	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

	[_window setBackgroundColor:CGColorCreate(colorSpace, transparentComponents)];
*/

	_screenView = [[ScreenView alloc] initWithFrame: rect];

	[_window setContentView:_screenView]; 
	[_window orderFront: self];
	[_window makeKey: self];
	[_window _setHidden: NO];
	
	[_screenView setBounds:CGRectMake(0,0,460,320)];
	
	//	[UIHardware deviceOrientation: TRUE];

	[self setStatusBarMode:4 orientation:90 duration:0.5 fenceID:0 animation: 0];

	[_screenView setRotationBy: 90.0f];
	[_screenView setBounds:CGRectMake(0,0,[_screenView bounds].size.width,[_screenView bounds].size.height)];
/*
UIImage* btnImage = [UIImage imageNamed:@"button_green.png"];
UIImage* btnImagePressed = [UIImage imageNamed:@"button_green_pressed.png"];
	
UIPushButton* pushButton = [[UIPushButton alloc] initWithTitle:@"Enter" autosizesToFit:NO];
[pushButton setFrame: CGRectMake(0.0, 0.0, 100.0, 50.0)];
[pushButton setDrawsShadow: YES];
[pushButton setEnabled:YES];  //may not be needed
[pushButton setStretchBackground:YES];

[pushButton setBackground:btnImage forState:0];  //up state
[pushButton setBackground:btnImagePressed forState:1]; //down state
*/
//[_screenView setButtonEnter:pushButton];

	pthread_create(&game_tid, NULL, game_thread, NULL);
}

- (void)applicationWillTerminate {
	[_window release];
}

/*
- (void)deviceOrientationChanged:(id)event {
    int orient = [ UIHardware deviceOrientation: YES ];

    float animDur = 0.5;
    int animType = 0;

    // handle status bar transition
    switch(orient) 
      {
      case kFACEUP:
      case kFACEDOWN:
	// do nothing for flat and face down
	break;

    case kUPSIDEDOWN:
      // Disable when upside down, there doesn't seem to be a
      // inverted status bar
      [self setStatusBarMode:2 orientation:180 duration:animDur fenceID:0 animation: animType];
      break;

    case kNORMAL:
      [self setStatusBarMode:4 orientation:0 duration:animDur fenceID:0 animation: animType];
      break;

    case kLANDL:
      [self setStatusBarMode:4 orientation:90 duration:animDur fenceID:0 animation: animType];
      break;

    case kLANDR:
      [self setStatusBarMode:4 orientation:-90 duration:animDur fenceID:0 animation: animType];

      break;
    }

    // pass orientation event over to top level app view
    [_screenView deviceOrientationChanged: orient];

    // no events when started from console
    //NSLog(@"orient: %d", orient);

}*/
@end
